<!--#
layout("/layouts/platform.html"){
#-->
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base!}/platform/goods/class" data-pjax id="goback"><i class="ti-angle-left"></i> ${msg['globals.button.back']}</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base!}/platform/goods/class/addDo" method="post">
                <div class="row mb10 mt10">
                    <div class="col-lg-12">
                        <div class="form-group has-feedback">
                            <label for="parentId" class="col-sm-2 control-label">${msg['goods.class.column.parentType']}</label>

                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input id="parentId" type="text" class="form-control" placeholder="${msg['goods.class.column.ifDoesNotChoose']}" disabled
                                           value="<!--#if(has(pobj)){#-->${pobj.name!}<!--#}#-->"/>

			                             		<span class="input-group-btn">
			                             			<button type="button" class="btn btn-primary" data-toggle="modal"
                                                            data-target="#dialogSelectParent"><i class="ti-plus"></i>${msg['goods.class.column.choose']}
                                                    </button>
			                             		</span>
                                </div>
                                <input type="hidden" name="parentId" value="<!--#if(has(pobj)){#-->${pobj.id!}<!--#}#-->">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="typeid" class="col-sm-2 control-label">${msg['goods.class.column.typeId']}</label>

                            <div class="col-sm-8">
                                <select id="typeId" name="typeId" class="form-control">
                                    <option value="">${msg['goods.class.column.generalMerchandise']}</option>
                                    <!--#for(o in typeList){
                                    #-->
                                    <option value="${o.id!}" <!--#if(has(pobj)&&pobj.typeId==o.id){#-->selected<!--#}#-->>${o.name!}</option>
                                    <!--#
                                    }#-->
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">${msg['goods.class.column.name']}</label>

                            <div class="col-sm-8">
                                <input type="text" id="name" class="form-control" name="name" data-parsley-required="true"
                                       placeholder="${msg['goods.class.column.name']}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="disabled" class="col-sm-2 control-label">${msg['goods.class.column.disabled']}</label>
                            <div class="col-sm-8 switcha">
                                <div class="mr15">
                                    <input type="checkbox" id="disabled" name="disabled" class="js-switch-red">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="${msg['globals.button.submit.tip']}">${msg['globals.button.submit']}</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>

    </div>
</div>
<a class="exit-offscreen"></a>
<!-- 选择上级 -->
<div id="dialogSelectParent" class="modal fade bs-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">${msg['goods.class.column.chooseParent']}</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div id="jsTreeParent" class="demo"></div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <div class="pull-left">
                    <button type="button" class="btn btn-success" data-dismiss="modal" onclick="selectFirstMenu()">${msg['goods.class.column.changeTop']}</button>
                </div>
                <button type="button" class="btn btn-default" data-dismiss="modal">${msg['globals.button.cancel']}</button>
                <button type="button" class="btn btn-primary" onclick="selectParent()">${msg['goods.class.column.enter']}</button>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">

    function initTreeView() {
        $("#jsTreeParent").jstree({
            plugins: ["wholerow", "json_data"],
            core: {
                data: {
                    dataType: "json",
                    url: function (node) {
                        return node.id === "#" ? "${base!}/platform/goods/class/tree" : "${base!}/platform/goods/class/tree?pid=" + node.id
                    }
                },
                multiple: false
            }
        }).on("dblclick.jstree", function (node) {
            selectParent();
        });
    }
    //选择父菜单
    function selectParent() {
        var tree = $.jstree.reference("#jsTreeParent");
        var node = tree.get_selected(true);
        $("#addForm #parentId").val(node[0].text);
        $("#addForm input[name='parentId']").val(node[0].id);
        $("#dialogSelectParent").modal("hide");
    }
    function selectFirstMenu() {
        $("#addForm #parentId").val("顶级分类");
        $("#addForm input[name='parentId']").val("");
        $("#dialogSelectParent").modal("hide");
    }
    $(document).ready(function () {
        initTreeView();
        myForm.init();
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                    Toast.success(data.msg);
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 1000);
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });
</script>


<!--#}#-->